From 9ffc1ef374ea337858a95142f77d4ed113f8c022 Mon Sep 17 00:00:00 2001 From: oliskoli Date: Tue, 8 Nov 2005 00:17:22 +0000 Subject: [PATCH] Handling of gpsbabel process and named pipe changed. git-svn-id: http://gpsbabel.googlecode.com/svn/trunk@1565 f51c46e8-681c-474f-0cfe-069cfd0219fb --- gpsbabel/win32/gui-2/utils.pas | 32 +++++++++++++++++++------------- 1 file changed, 19 insertions(+), 13 deletions(-) diff --git a/gpsbabel/win32/gui-2/utils.pas b/gpsbabel/win32/gui-2/utils.pas index c3f0c9a25..f9e44cbce 100644 --- a/gpsbabel/win32/gui-2/utils.pas +++ b/gpsbabel/win32/gui-2/utils.pas @@ -46,6 +46,7 @@ procedure FixStaticText(AComponent: TComponent); implementation uses + Forms, StdCtrls, common; @@ -70,6 +71,7 @@ var BytesRead, BytesDone: DWORD; buffer: packed array[0..512] of Char; Error: DWORD; + Wait_Result: DWORD; s: string; begin @@ -109,24 +111,28 @@ begin raise eGPSBabelError.CreateFmt( _('Could not run "gpsbabel.exe" (Error %d)!'), [Error]); end; - while (WaitforSingleObject (ProcessInfo.hProcess, 0)) <> WAIT_OBJECT_0 do sleep(100); - if not GetExitCodeProcess(ProcessInfo.hProcess, Error) then Error := 0; - - if (Error <> 0) and (Error <> 1) then - raise eGPSBabelError.CreateFmt(_('"gpsbabel.exe" returned error 0x%x (%d)'), [Error, Error]); s := ''; - PeekNamedPipe(hRead, nil, 0, nil, @BytesRead, nil); + repeat + Wait_Result := WaitforSingleObject(ProcessInfo.hProcess, 50); + if PeekNamedPipe(hRead, nil, 0, nil, @BytesRead, nil) then + begin + Application.ProcessMessages; + while (BytesRead > 0) do + begin + ReadFile(hRead, Buffer, SizeOf(buffer)-1, BytesDone, nil); + buffer[BytesDone] := #0; + s := s + string(buffer); + Dec(BytesRead, BytesDone); + end; + end; + until (Wait_Result = WAIT_OBJECT_0); - while (BytesRead > 0) do - begin - ReadFile(hRead, Buffer, SizeOf(buffer)-1, BytesDone, nil); - buffer[BytesDone] := #0; - s := s + string(buffer); + if not GetExitCodeProcess(ProcessInfo.hProcess, Error) then Error := 0; - Dec(BytesRead, BytesDone); - end; + if (Error <> 0) and (Error <> 1) then + raise eGPSBabelError.CreateFmt(_('"gpsbabel.exe" returned error 0x%x (%d)'), [Error, Error]); Output.Clear; Output.SetText(PChar(s)); -- 2.30.2